<?php 
include('./fun.php');include('./hd_fun.php');
$conn=my_sql($cfg);
$pass='';
$p=g('pass');
if($p!=$pass){exit;}

$ac=g('ac');
//$ac='pm';
switch($ac){
case 'data_analyze'://可以每间隔10分钟进行一次整理
$sql='select * from '.$cfg['e'].'pm where state=0 order by id asc limit 500';
$l=db($sql);
if(!$l){die('数据整理完毕');}
foreach($l as $v){
if(!$shop[$v['shop_id']]){
$sql='select total from '.$cfg['e'].'pm where shop_id="'.$v['shop_id'].'" and city="'.$v['city'].'" and state=1 order by id desc';
$l=db1($sql);
if($l){$shop[$v['shop_id']]=$l['total'];}else{$shop[$v['shop_id']]=0;}
}
$shop[$v['shop_id']]+=$v['jifen'];
$arr['total']=$shop[$v['shop_id']];
$arr['state']=1;
update($cfg['e'].'pm',$arr,' where id="'.$v['id'].'"');
echo $v['shop_id'].' '.$v['c'].'分析成功<br>';
}
break;

case 'pm'://进行城市分析 每间隔1小时可以执行一次 这个可能会耗费较多资源
$sql='select * from '.$cfg['e'].'pm where state=1 group by city,shop_id order by total desc';
$l=db($sql);
if($l){
foreach($l as $v){
if(!$city[$v['city']][$v['shop_id']]){$city[$v['city']][$v['shop_id']]=$v['city'];}
}

//print_r($city);

foreach($city as $v){
$num=0;
foreach($v as $k=>$t){
$num++;
$arr['no']=$num;
update($cfg['e'].'shop',$arr,' where id="'.$k.'" and dist="'.$t.'"');
}
}
}
break;




}


?>